package com.wwwarehouse.usercenter.fragment.permissiondistribute;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.wwwarehouse.common.custom_widget.popupwindow.EasyPopupWindow;
import com.wwwarehouse.common.tools.ApkTools;
import com.wwwarehouse.common.tools.PopUpUtils;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.response.InviteInfoResponseBean;
import com.wwwarehouse.usercenter.fragment.invite.InviteDetailsFragment;

import java.util.List;

/**
 * 查看不在线的联系人
 * Created by ShineF on 2017/9/25 0025.
 */

public class SelectNotOnlineFriendDetailsFragment extends InviteDetailsFragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void adapterListener(final List<InviteInfoResponseBean.InviteDetailsBean> inviteDetailList) {
        super.adapterListener(inviteDetailList);

        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                mInviteDetailsBean = inviteDetailList.get(i);
                callTa();
            }
        });
    }

    private void callTa() {
        mEasyPopupWindow = PopUpUtils.showPopUpBottom(R.layout.layout_contact_person, getContext(), mActivity.findViewById(android.R.id.content), true, childClickListener);
    }

    EasyPopupWindow.ChildClickListener childClickListener = new EasyPopupWindow.ChildClickListener() {
        @Override
        public void getChildView(int layoutId, View view) {
            view.findViewById(R.id.btn_wechat_contact).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
//                        Intent intent = new Intent(Intent.ACTION_MAIN);
//                        ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
//                        intent.addCategory(Intent.CATEGORY_LAUNCHER);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                        intent.setComponent(cmp);
//                        startActivity(intent);
                        ApkTools.launchWechat(mActivity);
                    } catch (Exception e) {
                        Toast.makeText(getContext(), "检查到您手机没有安装微信，请安装后使用该功能", Toast.LENGTH_LONG).show();
                    }
                }
            });

            view.findViewById(R.id.btn_phone_contact).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mInviteDetailsBean.getInviteeMobile()));
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                    startActivity(intent);
                }
            });

            view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mEasyPopupWindow.dismiss();
                }
            });
        }
    };
}
